!include "LogicLib.nsh"
!include "WordFunc.nsh"
!insertmacro WordAdd
!define REG_ENVIRONMENT "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
!define /date NOW "%Y%m%d"


; The name of the installer
Name "Fulguro"

; The file to write
OutFile "fulguro_setup_${NOW}.exe"

ShowInstDetails show
ShowUninstDetails show

; The default installation directory
InstallDir $PROGRAMFILES\Fulguro


Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

; The stuff to install
Section "Fulguro"

  SectionIn RO

  ; Set output path to the installation directory.

    CreateDirectory $INSTDIR\include
    CreateDirectory $INSTDIR\include\libpng12
    CreateDirectory $INSTDIR\include\SDL
    CreateDirectory $INSTDIR\bin
    CreateDirectory $INSTDIR\lib
    CreateDirectory $INSTDIR\lib\pkgconfig
    CreateDirectory $INSTDIR\pythonFulguro
    CreateDirectory $INSTDIR\pythonFulguro\fulguro
    CreateDirectory $INSTDIR\apps
    CreateDirectory $INSTDIR\apps\images
	CreateDirectory $INSTDIR\apps\images\bin
	CreateDirectory $INSTDIR\apps\images\gray
	CreateDirectory $INSTDIR\apps\images\color
    CreateDirectory $INSTDIR\apps\c
	CreateDirectory $INSTDIR\apps\c\example1
	CreateDirectory $INSTDIR\apps\c\example2
	CreateDirectory $INSTDIR\apps\c\example3
	CreateDirectory $INSTDIR\apps\c\example4
	CreateDirectory $INSTDIR\apps\c\example5
	CreateDirectory $INSTDIR\apps\c\example6
  	CreateDirectory $INSTDIR\apps\c\multithread
	CreateDirectory $INSTDIR\apps\c\multithread_auto
	CreateDirectory $INSTDIR\apps\python
	CreateDirectory $INSTDIR\apps\python\example1
	CreateDirectory $INSTDIR\apps\python\example2
	CreateDirectory $INSTDIR\apps\python\example3
	CreateDirectory $INSTDIR\apps\python\example4
	CreateDirectory $INSTDIR\apps\python\example5
	CreateDirectory $INSTDIR\apps\python\example6
  	CreateDirectory $INSTDIR\apps\python\example7
	CreateDirectory $INSTDIR\apps\python\example8
	CreateDirectory $INSTDIR\apps\python\example9
	CreateDirectory $INSTDIR\apps\python\multithread_auto

  SetOutPath $INSTDIR\include\libpng12
  File "include\libpng12\*.h"

  SetOutPath $INSTDIR\include\SDL
  File "include\SDL\*.h"

  SetOutPath $INSTDIR\include
  File "include\*.h"

  SetOutPath $INSTDIR\lib
  File "lib\*.*"

  SetOutPath $INSTDIR\bin
  File "bin\*.*"

  SetOutPath $INSTDIR\lib\pkgconfig
  File "lib\pkgconfig\*.*"

  SetOutPath $INSTDIR\pythonFulguro\fulguro
  File "pythonFulguro\fulguro\*.py"
  File "pythonFulguro\fulguro\*.pyd"
  File "pythonFulguro\fulguro\*.dll"

  SetOutPath $INSTDIR\apps\images\gray
  File "apps\images\gray\*.*"

  SetOutPath $INSTDIR\apps\images\bin
  File "apps\images\bin\*.*"

  SetOutPath $INSTDIR\apps\images\color
  File "apps\images\color\*.*"

  SetOutPath $INSTDIR\apps\python\example1
  File "apps\python\example1\*.py"

  SetOutPath $INSTDIR\apps\python\example2
  File "apps\python\example2\*.py"

  SetOutPath $INSTDIR\apps\python\example3
  File "apps\python\example3\*.py"

  SetOutPath $INSTDIR\apps\python\example4
  File "apps\python\example4\*.py"

  SetOutPath $INSTDIR\apps\python\example5
  File "apps\python\example5\*.py"

  SetOutPath $INSTDIR\apps\python\example6
  File "apps\python\example6\*.py"

  SetOutPath $INSTDIR\apps\python\example7
  File "apps\python\example7\*.py"

  SetOutPath $INSTDIR\apps\python\example8
  File "apps\python\example8\*.py"

  SetOutPath $INSTDIR\apps\python\example9
  File "apps\python\example9\*.py"

  SetOutPath $INSTDIR\apps\python\multithread_auto
  File "apps\python\multithread_auto\*.py"





  SetOutPath $INSTDIR\apps\c\example1
  File "apps\c\example1\*.c"

  SetOutPath $INSTDIR\apps\c\example2
  File "apps\c\example2\*.c"

  SetOutPath $INSTDIR\apps\c\example3
  File "apps\c\example3\*.c"

  SetOutPath $INSTDIR\apps\c\example4
  File "apps\c\example4\*.c"

  SetOutPath $INSTDIR\apps\c\example5
  File "apps\c\example5\*.c"

  SetOutPath $INSTDIR\apps\c\example6
  File "apps\c\example6\*.c"

  SetOutPath $INSTDIR\apps\c\multithread
  File "apps\c\multithread\*.c"

  SetOutPath $INSTDIR\apps\c\multithread_auto
  File "apps\c\multithread_auto\*.c"



	;shortcut
	CreateDirectory "$SMPROGRAMS\Fulguro"
	CreateShortCut "$SMPROGRAMS\Fulguro\Python Examples.lnk" "$INSTDIR\apps\python"
	CreateShortCut "$SMPROGRAMS\Fulguro\Documentation.lnk" "http://fulguro.sourceforge.net/modules.html"
	CreateShortCut "$SMPROGRAMS\Fulguro\Website.lnk" "http://fulguro.sourceforge.net"
	CreateShortCut "$SMPROGRAMS\Fulguro\uninstall.lnk" "$INSTDIR\uninstall.exe"


   ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\Fulguro "Install_Dir" "$INSTDIR"

  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Fulguro" "DisplayName" "Fulguro"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Fulguro" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Fulguro" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Fulguro" "NoRepair" 1

  ;Append to pythonpath fulguro python module directory
  Push $R0
	ReadRegStr $R0 HKLM "${REG_ENVIRONMENT}" "PYTHONPATH"

  ;test if $R0=""
  StrCmp $R0 "" 0 add
	${WordAdd} "$INSTDIR\pythonFulguro" "" "" $R0
add:
	${WordAdd} "$INSTDIR\pythonFulguro" ";" "+$R0" $R0


  WriteRegExpandStr HKLM "${REG_ENVIRONMENT}" "PYTHONPATH" "$R0"
	Pop $R0


	WriteUninstaller "uninstall.exe"

	Messagebox MB_OK "Added $INSTDIR\pythonFulguro to PYTHONPATH System Environment Variables"

SectionEnd

; Uninstaller

Section "Uninstall"
  Messagebox MB_OK "All programs using Fulguro must be closed before uninstall"

  RMDir /r "$INSTDIR"
	RMDir /r $SMPROGRAMS\Fulguro

SectionEnd
